package com.etone.smartFlow.controller;

import cn.hutool.poi.excel.ExcelUtil;
import com.etone.smartAudit.domain.flowable.SysDeployForm;
import com.etone.smartAudit.domain.flowable.SysForm;
import com.etone.smartFlow.common.AjaxResult;
import com.etone.smartFlow.domain.dto.FlowTaskDto;
import com.etone.smartFlow.domain.vo.TableDataInfo;
import com.etone.smartFlow.service.ISysDeployFormService;
import com.etone.smartFlow.service.ISysFormService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author jiayen
 * * @date 2022/01/06
 */
@Api(tags = "flow-表单引擎管理")
@RestController
@RequestMapping("/flowable/form")
public class SysFormController extends BaseController {

    @Autowired
    private ISysFormService SysFormService;

    @Autowired
    private ISysDeployFormService sysDeployFormService;

    /**
     * 查询流程表单列表
     */
    @ApiOperation(value = "查询流程表单列表", response = TableDataInfo.class)
    @GetMapping("/list")
    public TableDataInfo list(SysForm sysForm) {
        startPage();
        List<SysForm> list = SysFormService.selectSysFormList(sysForm);
        return getDataTable(list);
    }

    /**
     * 导出流程表单列表
     * TODO  暂不实现
     */

    @ApiOperation(value = "导出流程表单列表")
    @GetMapping("/export")
    public AjaxResult export(SysForm sysForm) {
        List<SysForm> list = SysFormService.selectSysFormList(sysForm);
//        ExcelUtil<SysForm> util = new ExcelUtil<SysForm>(SysForm.class);
//        return util.exportExcel(list, "form");
        return null;
    }

    /**
     * 获取流程表单详细信息
     */
    @ApiOperation(value = " 获取流程表单详细信息", response = SysForm.class)
    @GetMapping(value = "/{formId}")
    public AjaxResult getInfo(@PathVariable("formId") Long formId) {
        return AjaxResult.success(SysFormService.selectSysFormById(formId));
    }

    /**
     * 新增流程表单
     */
//    @PreAuthorize("@ss.hasPermi('flowable:form:add')")
//    @Log(title = "流程表单", businessType = BusinessType.INSERT)
    @ApiOperation(value = " 新增流程表单")
    @PostMapping
    public AjaxResult add(@RequestBody SysForm sysForm) {
        return toAjax(SysFormService.insertSysForm(sysForm));
    }

    /**
     * 修改流程表单
     */
//    @PreAuthorize("@ss.hasPermi('flowable:form:edit')")
//    @Log(title = "流程表单", businessType = BusinessType.UPDATE)
    @ApiOperation(value = " 修改流程表单")
    @PutMapping
    public AjaxResult edit(@RequestBody SysForm sysForm) {
        return toAjax(SysFormService.updateSysForm(sysForm));
    }

    /**
     * 删除流程表单
     */
//    @PreAuthorize("@ss.hasPermi('flowable:form:remove')")
//    @Log(title = "流程表单", businessType = BusinessType.DELETE)
    @ApiOperation(value = " 删除流程表单")
    @DeleteMapping("/{formIds}")
    public AjaxResult remove(@PathVariable Long[] formIds) {
        return toAjax(SysFormService.deleteSysFormByIds(formIds));
    }


    /**
     * 挂载流程表单
     */
//    @Log(title = "流程表单", businessType = BusinessType.INSERT)
    @ApiOperation(value = "挂载流程表单")
    @PostMapping("/addDeployForm")
    public AjaxResult addDeployForm(@RequestBody SysDeployForm sysDeployForm) {
        return toAjax(sysDeployFormService.insertSysDeployForm(sysDeployForm));
    }
}
